﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FunctionalCLR.Core {
    public class ListNode : FuncNode {

        public ListNode()
            : base() {
            base.Value = "list";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            foreach (Node child in Children) {
                child.Evaluate();
            }

            return this;
        }

        public override object Accept(IVisitor visitor) {
            return visitor.Visit(this);
        }

        public override string ToString() {
            StringBuilder buff = new StringBuilder();

            for(int index = 0; index < Children.Count; index++) {
                object value = Children[index].Evaluate();
                buff.Append(value);
                if (index + 1 < Children.Count) {
                    buff.Append(",");
                }
            }

            return buff.ToString();
        }
    }
}
